package io.magician.network.processing;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.http.HttpObjectAggregator;
import io.netty.handler.codec.http.HttpServerCodec;
import io.netty.handler.stream.ChunkedWriteHandler;


public class HttpServerInitializer extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new HttpServerCodec()); // http 编解码
        pipeline.addLast("httpAggregator",new HttpObjectAggregator(Integer.MAX_VALUE)); // http 消息聚合器
        pipeline.addLast("http-chunked",new ChunkedWriteHandler());
        pipeline.addLast(new HttpRequestHandler()); // 请求处理器
    }
}
